#include<stdio.h>
#define uint unsigned int
#define D(s) s=p[e++]-48;while(p[e]!=32&&p[e])s=10*s+p[e++]-48;e++;
typedef struct line 
{
	uint a:10;
	uint b:22;
	uint y;
}Line;

int compare(Line a,Line b)
{
	return a.y-b.y;
}

void swap(Line *arr,uint a,uint b) {
    Line t = arr[a];
    arr[a] = arr[b];
    arr[b] = t;
}


void Sort(Line *ar,uint i,uint j) {
	uint k,m;
	for (k=i;k<j-1;k++)
	{
		for (m=k+1;m<j;m++)
		{
			if (compare(ar[k],ar[m])>0)
			{
				swap(ar,k,m);
			}
		}
	}
}


void main()
{
	Line *ls=0;
	uint c,N,M,K,e,f,kn,res[50]={0},resn=0;
	char p[1000];
	gets(p);
	e=0;D(c)
	while(resn++<c)
	{
		gets(p);
		e=0;D(N)D(M)D(K)
			kn=K;
		if(M>0)
		{
			free(ls);
			ls=malloc(M*sizeof(Line));
			for (f=0;f<M;f++)
			{
				gets(p);
				e=0;D(ls[f].a)D(ls[f].b)D(ls[f].y)
			}
			Sort(ls,0,M);
			for (e=0;e<M;e++)
			{
				if (ls[e].a==K)
					kn=ls[e].b;
				else if(ls[e].b==K)
					kn=ls[e].a;
			}
		}
		if(kn==1||kn==2)
			res[resn-1]=1;
	}
	for (e=0;e<resn-2;e++)
	{
		if(res[e])
			puts("Yes");
		else
			puts("No");
	}
	if(res[e])
		printf("Yes");
	else
		printf("No");
}
